<?php
	include_once(dirname(__DIR__) . "/include/util.php");

	session_start();
	
	if(isset($_POST['login'])) {
		if ($_POST['username'] == 'benjamin' &&  $_POST['password'] == 'geheim')
			$_SESSION['loggedIn'] = true;
		header("Location: ".getUrl());
	}else if(isset($_POST['logout'])) {
		session_destroy();
		header("Location: ".getUrl());
	}
	
	
	echo "<div id=\"auth\">";
		if(!isset($_SESSION['loggedIn']) || !$_SESSION['loggedIn']) {
			echo	"<form action=\"".getUrl()."\" method=\"post\">".
						"<span>Username: <input type=\"text\" name=\"username\" /> Passwort: <input type=\"text\" name=\"password\" /></span>".
						"<input type=\"submit\" name=\"login\" value=\"login\" />".
					"</form>";
		}else{
			$username = $_POST['username'];
			$password = $_POST['password'];
			
			echo	"<form action=\"".getUrl()."\" method=\"post\">".
					"<span>Username: ".$username." Passwort: ".$password."</span>".
					"<input type=\"submit\" name=\"logout\" value=\"login\" />".
					"</form>";
		}
	echo "</div>";
?>